<? 

require_once('../includes/html2fpdf.php');
require_once('../Connections/locale.php');

$colname_codice_report = "1";
if (isset($_GET['id_report'])) {
  $colname_codice_report = (get_magic_quotes_gpc()) ? $_GET['id_report'] : addslashes($_GET['id_report']);
}
mysql_select_db($database_locale, $locale);
$query_codice_report = sprintf("SELECT nome, codice FROM reports WHERE id_report = %s", $colname_codice_report);
$codice_report = mysql_query($query_codice_report, $locale) or die(mysql_error());
$row_codice_report = mysql_fetch_assoc($codice_report);
$totalRows_codice_report = mysql_num_rows($codice_report);
$query = $row_codice_report['codice'];
$report_name=$row_codice_report['nome'];
mysql_free_result($codice_report);



error_reporting(0);




$report_name = str_replace(" ", "_",$report_name);
//$query = "SELECT * FROM aliquote";
$resultID = mysql_query($query, $locale) ;


// activate Output-Buffer:


//ob_start(); 

$pdf = new HTML2FPDF();
$pdf->DisableTags();
//$pdf->DisplayPreferences('FullScreen');


//echo $query;
 
$xml_output="<center><img src='Gestione_Abbonamenti_Logo.png'></center><br>";


$xml_output .="<table border=1 repeat_header=1>";
$xml_output .="<tr>";

for($y = 0 ; $y < mysql_num_fields($resultID) ; $y++){
	    $xml_output .= "<th>" . mysql_field_name($resultID, $y) . "</th>";
}

$xml_output .="</tr>";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);

    $xml_output .= "<tr>";

	for($y = 0 ; $y < mysql_num_fields($resultID) ; $y++){
	    $xml_output .= "<td>" . $row[mysql_field_name($resultID, $y)] . "</td>";
	}

    
    $xml_output .= "</tr>";
}

$xml_output .= "</table>";


//echo $xml_output;



$pdf->AddPage();
$pdf->WriteHTML($xml_output);
$pdf->Output($report_name.'.pdf','D'); 


?>

